package cn.szzsi.platform.service;

import cn.szzsi.model.Admin;
import cn.szzsi.model.PlatformResource;
import cn.szzsi.model.PlatformRoleResource;
import cn.szzsi.model.Resource;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by admin on 2017/7/10.
 */
public class AdminService {
    public static final AdminService service = new AdminService();

    /**
     * 超级管理员菜单权限
     *
     * @param
     * @param admin
     * @return
     */
    public void filterRoleResource(HttpServletRequest req, Admin admin) {
        StringBuffer sb = new StringBuffer();

        //查询所有资源
        List<PlatformResource> lbr1 = PlatformResource.dao.getByLevel(1);
        List<PlatformResource> lbr2 = PlatformResource.dao.getByLevel(2);
        List<PlatformResource> lbr3 = PlatformResource.dao.getByLevel(3);
        //根据角色来判断用户可以看到哪些资源
        System.out.println(admin.getRoleId());
        List<PlatformRoleResource> lbrr = PlatformRoleResource.dao.getByRoleId(admin.getRoleId());

        String ranks = org.apache.commons.lang3.StringUtils.EMPTY;
        for (PlatformRoleResource brr : lbrr) {
            ranks = ranks + "@" + brr.getResourceId();
        }

        req.setAttribute("lbr1", lbr1);
        req.setAttribute("lbr2", lbr2);
        req.setAttribute("lbr3", lbr3);
        req.setAttribute("ranks", ranks);

    }
}
